if (!require(readr)) {
  install.packages("readr")
}
## Loading required package: readr
if (!require(dplyr)) {
  install.packages("dplyr")
}
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
if (!require(ggplot2)) {
  install.packages("ggplot2")
}
## Loading required package: ggplot2
if (!require(GGally)) {
  install.packages("GGally")
}
## Loading required package: GGally
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
if (!require(tidyr)) {
  install.packages("tidyr")
}
## Loading required package: tidyr
if (!require(plotly)) {
  install.packages("plotly")
}
## Loading required package: plotly
## Warning: package 'plotly' was built under R version 4.3.2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
if (!require(tidyverse)) {
  install.packages("tidyverse")
}
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ plotly::filter() masks dplyr::filter(), stats::filter()
## ✖ dplyr::lag()     masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
if (!require(ppcor)) {
  install.packages("ppcor")
}
## Loading required package: ppcor
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## 
## The following object is masked from 'package:plotly':
## 
##     select
## 
## The following object is masked from 'package:dplyr':
## 
##     select
if (!require(MASS)) {
  install.packages("MASS")
}
if (!require(pwr)) {
  install.packages("pwr")
}
## Loading required package: pwr
if (!require(psych)) {
  install.packages("psych")
}
## Loading required package: psych
## 
## Attaching package: 'psych'
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
if (!require(corrplot)) {
  install.packages("corrplot")
}
## Loading required package: corrplot
## corrplot 0.92 loaded
if (!require(PerformanceAnalytics)) {
  install.packages("PerformanceAnalytics")
}
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'xts'
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## 
## Attaching package: 'PerformanceAnalytics'
## 
## The following object is masked from 'package:graphics':
## 
##     legend
if (!require(lubridate)) {
  install.packages("lubridate")
}
if (!require(feasts)) {
  install.packages("feasts")
}
## Loading required package: feasts
## Warning: package 'feasts' was built under R version 4.3.2
## Loading required package: fabletools
## Warning: package 'fabletools' was built under R version 4.3.2
if (!require(reshape2)) {
  install.packages("reshape2")
}
## Loading required package: reshape2
## Warning: package 'reshape2' was built under R version 4.3.2
## 
## Attaching package: 'reshape2'
## 
## The following object is masked from 'package:tidyr':
## 
##     smiths
if (!require(fable)) {
  install.packages("fable")
}
## Loading required package: fable
## Warning: package 'fable' was built under R version 4.3.2
if (!require(forecast)) {
  install.packages("forecast")
}
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 4.3.2
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
if (!require(foreign)) {
  install.packages("foreign")
}
## Loading required package: foreign
if (!require(fpp2)) {
  install.packages("fpp2")
}
## Loading required package: fpp2
## Warning: package 'fpp2' was built under R version 4.3.2
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.5 ──
## ✔ fma       2.5     ✔ expsmooth 2.3
## Warning: package 'fma' was built under R version 4.3.2
## Warning: package 'expsmooth' was built under R version 4.3.2
## ── Conflicts ───────────────────────────────────────────────── fpp2_conflicts ──
## ✖ psych::%+%()   masks ggplot2::%+%()
## ✖ psych::alpha() masks ggplot2::alpha()
if (!require(stats)) {
  install.packages("stats")
}
if (!require(tseries)) {
  install.packages("tseries")
}
## Loading required package: tseries
## Warning: package 'tseries' was built under R version 4.3.2
if (!require(astsa)) {
  install.packages("astsa")
}
## Loading required package: astsa
## 
## Attaching package: 'astsa'
## 
## The following objects are masked from 'package:fma':
## 
##     chicken, sales
## 
## The following object is masked from 'package:fpp2':
## 
##     oil
## 
## The following object is masked from 'package:forecast':
## 
##     gas
## 
## The following object is masked from 'package:psych':
## 
##     scatter.hist
if (!require(quantmod)) {
  install.packages("quantmod")
}
## Loading required package: quantmod
## Warning: package 'quantmod' was built under R version 4.3.2
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 4.3.2
if (!require(urca)) {
  install.packages("urca")
}
## Loading required package: urca
## Warning: package 'urca' was built under R version 4.3.2
library(readr)
library(dplyr)
library(ggplot2)
library(GGally)
library(tidyr)
library(plotly)
library(tidyverse)
library(ppcor)
library(MASS)
library(pwr)
library(psych)
library(corrplot)
library(PerformanceAnalytics)
library(lubridate)
library(feasts)
library(reshape2)
library(fable)
library(forecast)
library(foreign)
library(fpp2)
library(stats)
library(tseries)
library(astsa)
library(quantmod)
library(urca)

helper functions

# Function to analyze data range, check for duplicates, and missing values
analyze_data_quality <- function(data_frame) {
  # Data range
  date_range <- data_frame %>%
    summarize(
      min_datetime = min(datetime),
      max_datetime = max(datetime)
    )
  
  min_date <- format(date_range$min_datetime, format = "%Y-%m-%d %H:%M:%S")
  max_date <- format(date_range$max_datetime, format = "%Y-%m-%d %H:%M:%S")
  
  cat("Data is available in the date range from",
      min_date,
      "to",
      max_date, "\n")
  
  # Check for duplicates
  if (any(duplicated(data_frame))) {
    cat("There are duplicates in the dataset.\n")
  } else {
    cat("There are no duplicates in the dataset.\n")
  }
  
  # Check for missing values
  if (any(is.na(data_frame))) {
    cat("There are missing values in the dataset.\n")
  } else {
    cat("There are no missing values in the dataset.\n")
  }
}

Load data

pdm_telemetry <- read_csv(
  "data/PdM_telemetry.csv",
  col_types = cols(
    datetime = col_datetime(format = "%Y-%m-%d %H:%M:%S"),
    machineID = col_integer(),
    volt = col_double(),
    rotate = col_double(),
    pressure = col_double(),
    vibration = col_double()
  )
)
pdm_errors <- read_csv(
  "data/PdM_errors.csv",
  col_types = cols(
    datetime = col_datetime(format = "%Y-%m-%d %H:%M:%S"),
    machineID = col_integer(),
    errorID = col_character()
  )
)
pdm_maint <- read_csv(
  "data/PdM_maint.csv",
  col_types = cols(
    datetime = col_datetime(format = "%Y-%m-%d %H:%M:%S"),
    machineID = col_integer(),
    comp = col_character()
  )
)
pdm_failures <- read_csv(
  "data/PdM_failures.csv",
  col_types = cols(
    datetime = col_datetime(format = "%Y-%m-%d %H:%M:%S"),
    machineID = col_integer(),
    failure = col_character()
  )
)
pdm_machines <- read_csv(
  "data/PdM_machines.csv",
  col_types = cols(
    machineID = col_integer(),
    model = col_character(),
    age = col_integer()
  )
)
pdm_telemetry <- pdm_telemetry %>%
  arrange(datetime, machineID)

pdm_errors <- pdm_errors %>%
  arrange(datetime, machineID)

pdm_maint <- pdm_maint %>%
  arrange(datetime, machineID)

pdm_failures <- pdm_failures %>%
  arrange(datetime, machineID)

EDA: Telemetry

glimpse(pdm_telemetry)
## Rows: 876,100
## Columns: 6
## $ datetime  <dttm> 2015-01-01 06:00:00, 2015-01-01 06:00:00, 2015-01-01 06:00:…
## $ machineID <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1…
## $ volt      <dbl> 176.2179, 176.5589, 185.4820, 169.7108, 165.0829, 136.8786, …
## $ rotate    <dbl> 418.5041, 424.6242, 461.2111, 463.6467, 452.2836, 492.0884, …
## $ pressure  <dbl> 113.07794, 76.00533, 87.45320, 95.92988, 84.59172, 149.00358…
## $ vibration <dbl> 45.08769, 43.76705, 28.21686, 38.40037, 40.29880, 22.97329, …
head(pdm_telemetry)
## # A tibble: 6 × 6
##   datetime            machineID  volt rotate pressure vibration
##   <dttm>                  <int> <dbl>  <dbl>    <dbl>     <dbl>
## 1 2015-01-01 06:00:00         1  176.   419.    113.       45.1
## 2 2015-01-01 06:00:00         2  177.   425.     76.0      43.8
## 3 2015-01-01 06:00:00         3  185.   461.     87.5      28.2
## 4 2015-01-01 06:00:00         4  170.   464.     95.9      38.4
## 5 2015-01-01 06:00:00         5  165.   452.     84.6      40.3
## 6 2015-01-01 06:00:00         6  137.   492.    149.       23.0

n_machines

print("The number of unique machines in the pdm_telemetry dataset is:")
## [1] "The number of unique machines in the pdm_telemetry dataset is:"
print(pdm_telemetry %>%
    distinct(machineID) %>%
    nrow()
)
## [1] 100

Data Quality Check

analyze_data_quality(pdm_telemetry)
## Data is available in the date range from 2015-01-01 06:00:00 to 2016-01-01 06:00:00 
## There are no duplicates in the dataset.
## There are no missing values in the dataset.

Correlation and Distribution Scatterplot Matrix

ggpairs(pdm_telemetry, columns = c("volt", "rotate", "pressure", "vibration"))

Visualize Machine 1 Sensor Data

# Filter and select data for Machine 1
df_machine_1 <- pdm_telemetry %>%
  dplyr::filter(machineID == 1) 

# Reshape the data to long format
df_machine_1_long <- df_machine_1 %>%
  dplyr::select(datetime, volt, rotate, pressure, vibration) %>%
  tidyr::pivot_longer(cols = c(volt, rotate, pressure, vibration), names_to = "variable", values_to = "value")

# Create a facetted line plot
ggplot(df_machine_1_long, aes(x = datetime, y = value, color = variable)) +
  geom_line(size = 1) +
  labs(title = "Variables for Machine 1", xlabel = "Time", ylabel = "Value") +
  facet_wrap(~variable, scales = "free_y", ncol = 1)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Observations about Telemetry Data

  • This may be synthetically generated data distributed between 1st Jan 2015 to 1st Jan 2016.
  • Each row represents the state of a machine on a particular hour. Voltage, vibration, pressure & rotation of a machine have been averaged hourly.
  • There are 100 unique Machines.
  • There are no duplicates or missing values in the pdm_telemetry dataset.
  • The four parameters voltage, vibration, pressure & rotation are normally distributed.

EDA: Error

This data includes the errors encountered by the machines while in operating condition. Since, these errors don’t shut down the machines, these are not considered as failures. The error date and times are rounded to the closest hour since the telemetry data is collected at an hourly rate.

glimpse(pdm_errors)
## Rows: 3,919
## Columns: 3
## $ datetime  <dttm> 2015-01-01 06:00:00, 2015-01-01 06:00:00, 2015-01-01 06:00:…
## $ machineID <int> 24, 73, 81, 43, 14, 76, 42, 72, 75, 97, 10, 87, 94, 30, 19, …
## $ errorID   <chr> "error1", "error4", "error1", "error3", "error4", "error5", …
head(pdm_errors)
## # A tibble: 6 × 3
##   datetime            machineID errorID
##   <dttm>                  <int> <chr>  
## 1 2015-01-01 06:00:00        24 error1 
## 2 2015-01-01 06:00:00        73 error4 
## 3 2015-01-01 06:00:00        81 error1 
## 4 2015-01-01 07:00:00        43 error3 
## 5 2015-01-01 08:00:00        14 error4 
## 6 2015-01-01 08:00:00        76 error5

n_unique_errors

unique_errors <- pdm_errors %>%
  distinct(errorID) %>%
  nrow()

print("The number of unique errors in the pdm_errors dataset is:")
## [1] "The number of unique errors in the pdm_errors dataset is:"
print(unique_errors)
## [1] 5

Data Quality Check

analyze_data_quality(pdm_errors)
## Data is available in the date range from 2015-01-01 06:00:00 to 2016-01-01 05:00:00 
## There are no duplicates in the dataset.
## There are no missing values in the dataset.

Bar Plot of Different Error Types

# Create a bar plot for error types
plot <- ggplot(pdm_errors, aes(x = errorID)) +
  geom_bar() +
  labs(
    x = "Error Type",
    y = "Count",
    title = "Different Types of Errors"
  ) +
  theme_minimal()

print(plot)

Bar Plot of Errors Across MachineID

# Create a bar plot for errors across MachineID
plot <- ggplot(pdm_errors, aes(x = machineID)) +
  geom_bar() +
  coord_flip() +
  labs(
    x = "MachineID",
    y = "Count",
    title = "Number of Errors Across MachineID"
  ) +
  theme_minimal()

print(plot)

Machine-to-Error Distribution

# Group by machineID and errorID, count occurrences, and reset column names
df_errors <- pdm_errors %>%
  group_by(machineID, errorID) %>%
  summarise(errorValues = n()) %>%
  ungroup()
## `summarise()` has grouped output by 'machineID'. You can override using the
## `.groups` argument.
# Create a stacked bar plot for machine-to-error distribution
plot <- ggplot(df_errors, aes(x = factor(machineID), y = errorValues, fill = errorID)) +
  geom_bar(stat = "identity", position = "stack", width = 0.8) +
  labs(
    x = "Machine ID",
    y = "Number of Errors",
    title = "Count of Errors for Different Machines"
  ) +
  theme_minimal() +
  theme(legend.position = "top")  # Move the legend to the top

print(plot)

Plot Number of Errors Across Machines Over Days

# Count errors by date and sort by index
errors_count <- table(as.Date(pdm_errors$datetime))

# Create a time series plot for the number of errors across days
plot <- ggplot(data.frame(date = as.Date(names(errors_count)), count = as.numeric(errors_count)), aes(x = date, y = count)) +
  geom_line(size = 1) +
  labs(
    x = "Time",
    y = "Number of Errors",
    title = "Number of Errors Across Days"
  ) +
  theme_minimal()

print(plot)

Distribution of the Number of Errors Per Day Across Machines

# Convert datetime to date in the pdm_errors
pdm_errors$date <- as.Date(pdm_errors$datetime)

# Group by date, count occurrences, and create a histogram
errors_per_day <- pdm_errors %>%
  group_by(date) %>%
  summarise(ErrorCount = n())

# Create a histogram of the number of errors per day
plot <- ggplot(errors_per_day, aes(x = ErrorCount)) +
  geom_histogram(binwidth = 1, fill = "blue", color = "black") +
  labs(
    x = "Number of Errors on a Particular Day",
    y = "Frequency",
    title = "Distribution of Number of Errors Per Day"
  ) +
  theme_minimal()

print(plot)

EDA: Maintenance

If a component of a machine is replaced, that is captured as a record in this table. Components are replaced under two situations: - During the regular scheduled visit, the technician replaced it (Proactive Maintenance) - A component breaks down and then the technician does an unscheduled maintenance to replace the component (Reactive Maintenance). This is considered as a failure and corresponding data is captured under Failures. Maintenance data has both 2014 and 2015 records. This data is rounded to the closest hour since the telemetry data is collected at an hourly rate.

glimpse(pdm_maint)
## Rows: 3,286
## Columns: 3
## $ datetime  <dttm> 2014-06-01 06:00:00, 2014-06-01 06:00:00, 2014-06-01 06:00:…
## $ machineID <int> 1, 6, 9, 9, 11, 16, 18, 19, 20, 20, 21, 26, 37, 39, 40, 41, …
## $ comp      <chr> "comp2", "comp2", "comp1", "comp2", "comp2", "comp4", "comp3…
head(pdm_maint)
## # A tibble: 6 × 3
##   datetime            machineID comp 
##   <dttm>                  <int> <chr>
## 1 2014-06-01 06:00:00         1 comp2
## 2 2014-06-01 06:00:00         6 comp2
## 3 2014-06-01 06:00:00         9 comp1
## 4 2014-06-01 06:00:00         9 comp2
## 5 2014-06-01 06:00:00        11 comp2
## 6 2014-06-01 06:00:00        16 comp4

Data Quality Check

analyze_data_quality(pdm_maint)
## Data is available in the date range from 2014-06-01 06:00:00 to 2016-01-01 06:00:00 
## There are no duplicates in the dataset.
## There are no missing values in the dataset.

Maintenance data is present June 2014 onwards. This is different from other data which are present between 2015 and 2016.

Plot Number of Maintenance Records Across Months

# Extract month and year from datetime column
pdm_maint <- pdm_maint %>%
  mutate(month_year = format(datetime, "%Y-%m"))

# Create a bar plot for the number of maintenance records across months and years
plot <- ggplot(pdm_maint, aes(x = month_year)) +
  geom_bar() +
  labs(
    x = "Month-Year",
    y = "Number of Maintenance Records",
    title = "Number of Maintenance Records Across Months and Years"
  ) +
  theme_minimal()

print(plot)

Number of components replaced in the year 2015 are considerably higher compared to the 2014.

Components Replaced

# Create a bar plot for the number of components replaced
plot <- ggplot(pdm_maint, aes(x = comp)) +
  geom_bar() +
  labs(
    x = "Component",
    y = "Count",
    title = "Components Replaced"
  ) +
  theme_minimal()

print(plot)

Four types components are replaced almost in the same numbers.

Number of Maintenance Records Across Machines

# Create a bar plot for the number of maintenance records across machine IDs
plot <- ggplot(pdm_maint, aes(x = factor(machineID))) +
  geom_bar() +
  coord_flip() +
  labs(
    x = "Machine ID",
    y = "Number of Maintenance Records",
    title = "Number of Maintenance Records Across Machine IDs"
  ) +
  theme_minimal()

print(plot)

Machine to Components Replaced

# Group by machineID and comp, count occurrences, and reset column names
df_maint <- pdm_maint %>%
  group_by(machineID, comp) %>%
  summarise(num_comp = n()) %>%
  ungroup()
## `summarise()` has grouped output by 'machineID'. You can override using the
## `.groups` argument.
# Create a stacked bar plot for machine-to-components replaced
plot <- ggplot(df_maint, aes(x = factor(machineID), y = num_comp, fill = comp)) +
  geom_bar(stat = "identity", position = "stack", width = 0.8) +
  labs(
    x = "Machine ID",
    y = "Number of Components Replaced",
    title = "Count of Components Replaced for Different Machines"
  ) +
  theme_minimal() +
  theme(legend.position = "top")  # Move the legend to the top

print(plot)

Number of Maintenance Issues Raised Per Day

# Count the number of maintenance records per day and create a time series plot
plot <- ggplot(data = pdm_maint, aes(x = as.Date(datetime))) +
  geom_point(aes(y = after_stat(count)), stat = "count", color = "black") +
  labs(
    x = "Time",
    y = "Number of Maintenance Records",
    title = "Number of Maintenance Records Across Time"
  ) +
  theme_minimal()

print(plot)

This indicates that there is a drastic difference between the number of maintenance records in 2014 vs 2015.

#EDA machines This data set includes some information about the machines: model type and age (years in service).

glimpse(pdm_machines)
## Rows: 100
## Columns: 3
## $ machineID <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1…
## $ model     <chr> "model3", "model4", "model3", "model3", "model3", "model3", …
## $ age       <int> 18, 7, 8, 7, 2, 7, 20, 16, 7, 10, 6, 9, 15, 1, 14, 3, 14, 15…
head(pdm_machines)
## # A tibble: 6 × 3
##   machineID model    age
##       <int> <chr>  <int>
## 1         1 model3    18
## 2         2 model4     7
## 3         3 model3     8
## 4         4 model3     7
## 5         5 model3     2
## 6         6 model3     7

Distribution of Machine Ages

# Create a box plot for the distribution of machine ages
plot <- ggplot(pdm_machines, aes(y = age)) +
  geom_boxplot() +
  labs(
    y = "Machine Age",
    title = "Distribution of Machine Ages"
  ) +
  theme_minimal()

print(plot)

The age of the Machines is distributed between 0 to 20. The median age is to ~12.5. There are no outliers. Another indication that this is a synthetic data.

Machine Age Distribution

# Create a plotly figure
fig <- plot_ly()

# Add histogram traces for each model
fig <- fig %>% add_trace(
  data = pdm_machines %>%
    filter(model == "model1"),
  x = ~age,
  name = "model1",
  type = "histogram"
)

fig <- fig %>% add_trace(
  data = pdm_machines %>%
    filter(model == "model2"),
  x = ~age,
  name = "model2",
  type = "histogram"
)

fig <- fig %>% add_trace(
  data = pdm_machines %>%
    filter(model == "model3"),
  x = ~age,
  name = "model3",
  type = "histogram"
)

fig <- fig %>% add_trace(
  data = pdm_machines %>%
    filter(model == "model4"),
  x = ~age,
  name = "model4",
  type = "histogram"
)

# Customize layout
fig <- fig %>% layout(
  xaxis = list(title = "Age"),
  yaxis = list(title = "Count"),
  barmode = "stack",
  title = "Machine Age Distribution"
)

# Display the plot
fig

#EDA failures

glimpse(pdm_failures)
## Rows: 761
## Columns: 3
## $ datetime  <dttm> 2015-01-02 03:00:00, 2015-01-02 03:00:00, 2015-01-02 03:00:…
## $ machineID <int> 16, 16, 17, 22, 35, 45, 51, 56, 58, 59, 73, 79, 80, 83, 86, …
## $ failure   <chr> "comp1", "comp3", "comp4", "comp1", "comp1", "comp1", "comp1…
head(pdm_failures)
## # A tibble: 6 × 3
##   datetime            machineID failure
##   <dttm>                  <int> <chr>  
## 1 2015-01-02 03:00:00        16 comp1  
## 2 2015-01-02 03:00:00        16 comp3  
## 3 2015-01-02 03:00:00        17 comp4  
## 4 2015-01-02 03:00:00        22 comp1  
## 5 2015-01-02 03:00:00        35 comp1  
## 6 2015-01-02 03:00:00        45 comp1

Data Quality Check

analyze_data_quality(pdm_failures)
## Data is available in the date range from 2015-01-02 03:00:00 to 2015-12-31 06:00:00 
## There are no duplicates in the dataset.
## There are no missing values in the dataset.

Count of Failures

# Create a plotly bar chart
fig <- plot_ly(pdm_failures, x = ~failure, type = "histogram") %>%
  layout(
    title = "Count of Failures",
    xaxis = list(title = "Failure Type"),
    yaxis = list(title = "Count"),
    template = "plotly_dark"
  )

# Display the plot
fig

Predictive Model

combined_data <- pdm_telemetry %>%
  full_join(pdm_failures, by = c("machineID", "datetime"))
# Create a summary of the number of days with and without failures
combined_data <- combined_data %>%
  mutate(has_failure = datetime %in% pdm_failures$datetime)
summary_data <- combined_data %>%
  group_by(has_failure) %>%
  summarise(count = n())
ggplot(summary_data, aes(x = factor(has_failure), y = count, fill = factor(has_failure))) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = c("red", "green")) + 
  labs(x = "Machine failure", y = "Number of Days") +
  theme_minimal()

total_failures <- sum(combined_data$has_failure)
total_failures
## [1] 30242
library(lubridate)

# Suppose datetime is a column of combined_data
# Extract datetime components
combined_data$year <- year(combined_data$datetime)
combined_data$month <- month(combined_data$datetime)
combined_data$day <- day(combined_data$datetime)
combined_data$hour <- hour(combined_data$datetime)

# Create a new column for the day of the week
combined_data$weekday <- wday(combined_data$datetime, label = TRUE)

# Create a new column for the day of the year
combined_data$day_of_year <- yday(combined_data$datetime)
# Filter rows with non-null values in the variable 'failure'.
filtered_data <- combined_data[!is.na(combined_data$failure), ]

# Group data by month and count total failures
monthly_failures <- filtered_data %>%
  group_by(month) %>%
  summarise(total_failures = sum(!is.na(failure)))

# Create a seasonal chart for total failures
ggplot(monthly_failures, aes(x = month, y = total_failures)) +
  geom_bar(stat = "identity", fill = "lightcoral") +
  labs(title = "Seasonal Pattern of Total Failures",
       x = "Month", y = "Number of Total Failures") +
  theme_minimal()

combined_data <- combined_data %>% 
  mutate(failure_indicator = ifelse(!is.na(failure), 1, 0)) %>%
  group_by(datetime) %>%
  summarise(total_failures = sum(failure_indicator))
# Create a time series of total_failures with hourly frequency (24) and set the start time.
total_failures.ts <- ts(combined_data$total_failures, 
                        start = c(2015, 1, 1, 6),  # Adjust the start-up to January 1, 2015
                        frequency = 1)

total_failures.ts
## Time Series:
## Start = 2015 
## End = 10775 
## Frequency = 1 
##    [1]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 18  0  0
##   [25]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##   [49]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##   [73]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##   [97]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [121]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [145]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [169]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [193]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [217]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [241]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [265]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [289]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [313]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [337]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [361]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [385]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [409]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [433]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [457]  7  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [481]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [505]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [529]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [553]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [577]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [601]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [625]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [649]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [673]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [697]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [721]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [745]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [769]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [793]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [817]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [841]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [865]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [889]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [913]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [937]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [961]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
##  [985]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1009]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1033]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1057]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1081]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1105]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1129]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1153]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1177]  6  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1201]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1225]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1249]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1273]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1297]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1321]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1345]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1369]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1393]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1417]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1441]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1465]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1489]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1513]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1537]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1561]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1585]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1609]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1633]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1657]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1681]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1705]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1729]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1753]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1777]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1801]  6  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1825]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1849]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1873]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1897]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1921]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1945]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1969]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [1993]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2017]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2041]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2065]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2089]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2113]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2137]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2161]  6  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2185]  8  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2209]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2233]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2257]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2281]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2305]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2329]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2353]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2377]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2401]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2425]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2449]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2473]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2497]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2521]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2545]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2569]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2593]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2617]  7  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2641]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2665]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2689]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2713]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2737]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2761]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2785]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2809]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2833]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2857]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2881]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2905]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2929]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2953]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [2977]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3001]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3025]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3049]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3073]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3097]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3121]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3145]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3169]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3193]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3217]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3241]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3265]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3289]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3313]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3337]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3361]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3385]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3409]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3433]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3457]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3481]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3505]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3529]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3553]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3577]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3601]  6  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3625]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3649]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3673]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3697]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3721]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3745]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3769]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3793]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3817]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3841]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3865]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3889]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3913]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3937]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3961]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [3985]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4009]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4033]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4057]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4081]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4105]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4129]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4153]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4177]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4201]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4225]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4249]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4273]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4297]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4321]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4345]  6  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4369]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4393]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4417]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4441]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4465]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4489]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4513]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4537]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4561]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4585]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4609]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4633]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4657]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4681]  6  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4705]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4729]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4753]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4777]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4801]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4825]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4849]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4873]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4897]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4921]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4945]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4969]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [4993]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5017]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5041]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5065]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5089]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5113]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5137]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5161]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5185]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5209]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5233]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5257]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5281]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5305]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5329]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5353]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5377]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5401]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5425]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5449]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5473]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5497]  6  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5521]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5545]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5569]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5593]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5617]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5641]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5665]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5689]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5713]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5737]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5761]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5785]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5809]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5833]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5857]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5881]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5905]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5929]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5953]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [5977]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6001]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6025]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6049]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6073]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6097]  6  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6121]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6145]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6169]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6193]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6217]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6241]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6265]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6289]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6313]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6337]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6361]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6385]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6409]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6433]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6457]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6481]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6505]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6529]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6553]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6577]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6601]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6625]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6649]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6673]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6697]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6721]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6745]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6769]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6793]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6817]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6841]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6865]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6889]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6913]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6937]  6  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6961]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [6985]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7009]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7033]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7057]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7081]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7105]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7129]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7153]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7177]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7201]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7225]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7249]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7273]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7297]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7321]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7345]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7369]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7393]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7417]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7441]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7465]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7489]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7513]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7537]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7561]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7585]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7609]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7633]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7657]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7681]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7705]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7729]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7753]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7777]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7801]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7825]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7849]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7873]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7897]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7921]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7945]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7969]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [7993]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8017]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8041]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8065]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8089]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8113]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8137]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8161]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8185]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8209]  7  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8233]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8257]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8281]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8305]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8329]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8353]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8377]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8401]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8425]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8449]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8473]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8497]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8521]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8545]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8569]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8593]  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8617]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8641]  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8665]  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8689]  2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8713]  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8737]  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
## [8761]  0
plot(total_failures.ts)

adf.test(total_failures.ts)
## Warning in adf.test(total_failures.ts): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  total_failures.ts
## Dickey-Fuller = -29.041, Lag order = 20, p-value = 0.01
## alternative hypothesis: stationary
total_failures_log <- log(total_failures.ts)
total_failures_log <- total_failures_log[!is.na(total_failures_log) & is.finite(total_failures_log)]

# Comprueba si hay suficientes datos no NA y finitos para realizar el test ADF
if (length(total_failures_log) > 0) {
  plot(total_failures_log)
  
  # Realiza el test ADF
  ur.df_result <- ur.df(total_failures_log, type = "none", selectlags = "AIC")
  summary(ur.df_result)
} else {
  cat("No hay suficientes datos no NA y finitos para realizar el test ADF.\n")
}

## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.4097 -0.3222  0.1535  0.6578  1.9459 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -0.22143    0.04376  -5.059 7.37e-07 ***
## z.diff.lag -0.31296    0.05414  -5.781 1.87e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6535 on 298 degrees of freedom
## Multiple R-squared:  0.2438, Adjusted R-squared:  0.2388 
## F-statistic: 48.05 on 2 and 298 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -5.0595 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
modelT=auto.arima(total_failures.ts)
modelT
## Series: total_failures.ts 
## ARIMA(1,0,1) with non-zero mean 
## 
## Coefficients:
##          ar1      ma1    mean
##       0.8701  -0.9141  0.0868
## s.e.  0.0161   0.0128  0.0039
## 
## sigma^2 = 0.3075:  log likelihood = -7264.58
## AIC=14537.17   AICc=14537.17   BIC=14565.48
summary(modelT)
## Series: total_failures.ts 
## ARIMA(1,0,1) with non-zero mean 
## 
## Coefficients:
##          ar1      ma1    mean
##       0.8701  -0.9141  0.0868
## s.e.  0.0161   0.0128  0.0039
## 
## sigma^2 = 0.3075:  log likelihood = -7264.58
## AIC=14537.17   AICc=14537.17   BIC=14565.48
## 
## Training set error measures:
##                        ME      RMSE       MAE MPE MAPE      MASE       ACF1
## Training set 0.0001063631 0.5544683 0.1718132 NaN  Inf 0.9888856 0.01193596
par(mar=c(5, 4, 2, 2))
tsdiag(modelT)

#Ruido blanco
Box.test(residuals(modelT), type = "Ljung-Box")
## 
##  Box-Ljung test
## 
## data:  residuals(modelT)
## X-squared = 1.2486, df = 1, p-value = 0.2638
error_modelT=residuals(modelT)
plot(error_modelT)

#Realizamos la predicción
predictT <- forecast::forecast(modelT, h = 30)
predictT
##       Point Forecast      Lo 80     Hi 80      Lo 95    Hi 95
## 10776     0.10898934 -0.6017121 0.8196908 -0.9779347 1.195913
## 10777     0.10610757 -0.6052819 0.8174971 -0.9818688 1.194084
## 10778     0.10360026 -0.6083097 0.8155102 -0.9851720 1.192373
## 10779     0.10141876 -0.6108849 0.8137224 -0.9879557 1.190793
## 10780     0.09952072 -0.6130808 0.8121223 -0.9903093 1.189351
## 10781     0.09786932 -0.6149576 0.8106963 -0.9923054 1.188044
## 10782     0.09643251 -0.6165651 0.8094301 -0.9940032 1.186868
## 10783     0.09518239 -0.6179443 0.8083091 -0.9954508 1.185816
## 10784     0.09409472 -0.6191297 0.8073191 -0.9966879 1.184877
## 10785     0.09314839 -0.6201500 0.8064468 -0.9977473 1.184044
## 10786     0.09232502 -0.6210294 0.8056794 -0.9986563 1.183306
## 10787     0.09160864 -0.6217881 0.8050054 -0.9994375 1.182655
## 10788     0.09098535 -0.6224435 0.8044142 -1.0001099 1.182081
## 10789     0.09044305 -0.6230101 0.8038962 -1.0006893 1.181575
## 10790     0.08997122 -0.6235003 0.8034427 -1.0011893 1.181132
## 10791     0.08956070 -0.6239247 0.8030461 -1.0016211 1.180742
## 10792     0.08920352 -0.6242924 0.8026995 -1.0019944 1.180401
## 10793     0.08889276 -0.6246112 0.8023967 -1.0023173 1.180103
## 10794     0.08862237 -0.6248876 0.8021323 -1.0025969 1.179842
## 10795     0.08838712 -0.6251274 0.8019017 -1.0028392 1.179613
## 10796     0.08818244 -0.6253355 0.8017004 -1.0030492 1.179414
## 10797     0.08800436 -0.6255163 0.8015250 -1.0032312 1.179240
## 10798     0.08784941 -0.6256732 0.8013720 -1.0033892 1.179088
## 10799     0.08771460 -0.6258095 0.8012387 -1.0035263 1.178956
## 10800     0.08759731 -0.6259279 0.8011225 -1.0036454 1.178840
## 10801     0.08749526 -0.6260308 0.8010213 -1.0037487 1.178739
## 10802     0.08740647 -0.6261203 0.8009332 -1.0038385 1.178651
## 10803     0.08732922 -0.6261980 0.8008564 -1.0039165 1.178575
## 10804     0.08726200 -0.6262656 0.8007896 -1.0039843 1.178508
## 10805     0.08720352 -0.6263244 0.8007314 -1.0040432 1.178450
plot(predictT)